package main

import (
	"fmt"
	"math"
	"regexp"
)

func main() {
	GetSimilarity("黔南西州", "黔南布依族苗族自治州")
}

func GetSimilarity(doc1, doc2 string) {
	mp := make(map[int][]int)
	for _, v := range doc1 {
		if IsHanZi(v) {
			fq, ok := mp[int(v)]
			if ok {
				fq[0]++
			} else {
				mp[int(v)] = []int{1, 0}
			}
		}
	}
	for _, v := range doc2 {
		if IsHanZi(v) {
			fq, ok := mp[int(v)]
			if ok {
				fq[1]++
			} else {
				mp[int(v)] = []int{0, 1}
			}
		}
	}
	var sqdoc1, sqdoc2, denominator float64
	for k, _ := range mp {
		c := mp[k]
		denominator += float64(c[0]) * float64(c[1])
		sqdoc1 += float64(c[0]) * float64(c[0])
		sqdoc2 += float64(c[1]) * float64(c[1])
	}
	res := denominator / math.Sqrt(sqdoc1*sqdoc2)
}

func IsHanZi(str rune) bool {
	var hzRegexp = regexp.MustCompile("^[\u4e00-\u9fa5]$")
	return hzRegexp.MatchString(string(str))
}
